package com.fileOperate;

import it.sauronsoftware.jave.Encoder;
import it.sauronsoftware.jave.EncoderException;
import it.sauronsoftware.jave.MultimediaInfo;

import java.io.File;

/**
 * @author chenqb
 * @Description 遍历所有视频，获取视频时长 操作
 */
public class ReadVideo {

    public static void main(String[] args) throws EncoderException {
        Encoder encoder = new Encoder();
        long totalTime = 0;
        String path = "D:\\Download\\BaiduNetdiskDownload\\大学数学同步课程-线性代数\\线性代数";        //要遍历的路径
        File file = new File(path);        //获取其file对象
        File[] fs = file.listFiles();    //遍历path下的文件和目录，放在File数组中
        for (File f : fs) {                    //遍历File[]数组
            if (!f.isDirectory()) {        //若非目录(即文件)，则打印
                MultimediaInfo m = encoder.getInfo(f);
                long ls = m.getDuration();
                totalTime = ls + totalTime;
            }


//        File source=  new  File( "E:\\测试视频\\R41.avi" );
//        Encoder encoder =  new  Encoder();
//        try  {
//           MultimediaInfo m = encoder.getInfo(source);
//           long  ls = m.getDuration();
//        }  catch (Exception e) {
//          e.printStackTrace();
        }
        System.out.println("此视频时长为:" +totalTime/3600000+"小时"+ totalTime / 60000 + "分" + totalTime / 1000 + "秒！");

    }
}